package com.leetcode.merci.lc003;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by bowen on 2017/8/1.
 */
public class Solution {
    public int lengthOfLongestSubstring(String s) {
        if(s.length()==0){
            return 0;
        }
        int max=1;
        int count=1;
        Map<String,String> map=new HashMap<String,String>();
        for(int i=0,j=0;i<s.length()&&j<s.length();){
            if(map.get(s.substring(j,j+1))==null){
                map.put(s.substring(j,j+1),"1");
                j++;
                if(j-i>max){
                    max=j-i;
                }
            }
            else{
                while(!s.substring(j,j+1).equals(s.substring(i,i+1))){
                    map.remove(s.substring(i,i+1));
                    i++;
                }
                map.remove(s.substring(i,i+1));
                i++;
            }
        }
        return max;

    }

    public static void main(String[] args) {
        Solution solution=new Solution();
        System.out.println(solution.lengthOfLongestSubstring("bbbbb"));
    }
}